//
//  HJSignatureVC.m
//  project
//
//  Created by jc on 2019/5/8.
//  Copyright © 2019 健健. All rights reserved.
//

#import "HJSignatureVC.h"

@interface HJSignatureVC ()
@property (weak, nonatomic) IBOutlet UIView *bgView;
@property (weak, nonatomic) IBOutlet UITextField *signatureTF;
@property (weak, nonatomic) IBOutlet UIButton *commitBtn;

@end

@implementation HJSignatureVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.navTitle = @"修改个性签名";
    self.signatureTF.text = [HJUserManager getUserModel].intro;
    [self.commitBtn rounded:UIRectCornerAllCorners radius:6];
    [self.view setupShadowWithView:self.bgView];
    @weakify(self)
    [[self.signatureTF.rac_textSignal filter:^BOOL(NSString * _Nullable value) {
        return value.length >=16;
    }]subscribeNext:^(NSString * _Nullable x) {
        @strongify(self)
        self.signatureTF.text = [x substringToIndex:16];
    }];
    
    RAC(self.commitBtn,userInteractionEnabled) = [RACSignal combineLatest:@[self.signatureTF.rac_textSignal] reduce:^id (NSString * name){
        @strongify(self)
        if (!name.length) {
            [self.commitBtn setBackgroundColor:UIColor.lightGrayColor];
            return @NO;
        }
        [self.commitBtn setBackgroundColor:UIColor.blackColor];
        return @YES;
    }];
    
    [[self.commitBtn rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
        @strongify(self)
        [HJUserManager updateUserModelWithParams:@{@"intro":self.signatureTF.text} success:^{
            [self.navigationController popViewControllerAnimated:YES];
        }];
    }];
}



@end
